<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root"></div>
    <script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
    <script type="text/babel">
        class MyComponent extends React.Component{
            constructor(){
                super();
                this.input = React.createRef();
                this.state = {count:0,value:"默认值",gender:"女"}
            }
            handleClick = () => {
                console.log(this.state.value,this.state.gender);
                // console.log("click",this.input.current.value);
            }
            handleAdd = () => {
                this.setState({
                    count:this.state.count + 1
                });
                console.log(this.state.count);
            }
            handleInput = (e) => {
                this.setState({
                    value:e.target.value
                });
            }
            render(){
                return <div>
                        <div>
                            <input type="text" ref={this.input} 
                            onInput={this.handleInput} 
                            value={this.state.value}/>
                            <input type="button" value="ok" onClick={this.handleClick} />
                            <input type="radio" name="gender" 
                            checked={this.state.gender == "男" ? true : false}
                            onChange={(e) => this.setState({gender:e.target.value})}
                            value="男" /><label>男</label>
                            
                            <input type="radio" name="gender"
                            checked={this.state.gender == "女" ? true : false}
                            onChange={(e) => this.setState({gender:e.target.value})}
                            value="女" /><label>女</label>
                        </div>
                        <div>
                            <label>计数器：{this.state.count}</label>  
                            <input type="button" value="加1" onClick={this.handleAdd} />
                        </div>
                    </div>
            }
        }
        ReactDOM.render(<MyComponent />,document.getElementById("root"));
    </script>
</body>
</html>